<template>
  <div class="t-sales">
    <div class="t-sales-head">
      <h5>销售统计</h5>
    </div>
    <div class="t-sales-content">
      <div ref="chartDom" style="width: 100%; height: 400px"></div>
    </div>
  </div>
</template>

<script setup name="SalesChart">
import * as echarts from 'echarts';
const { proxy } = getCurrentInstance();

const chartDom = ref(null);
let myChart = null;

const initChart = () => {
  myChart = echarts.init(chartDom.value);
  let option = {
    tooltip: {
      trigger: 'item'
    },
    legend: {
      top: '5%',
      left: 'center'
    },
    series: [
      {
        name: 'Access From',
        type: 'pie',
        radius: ['40%', '70%'],
        avoidLabelOverlap: false,
        padAngle: 5,
        itemStyle: {
          borderRadius: 10
        },
        label: {
          show: false,
          position: 'center'
        },
        emphasis: {
          label: {
            show: true,
            fontSize: 40,
            fontWeight: 'bold'
          }
        },
        labelLine: {
          show: false
        },
        data: [
          { value: 1048, name: 'Search Engine' },
          { value: 735, name: 'Direct' },
          { value: 580, name: 'Email' },
          { value: 484, name: 'Union Ads' },
          { value: 300, name: 'Video Ads' }
        ]
      }
    ]
  };

  option && myChart.setOption(option);
}

// 初始化饼图
onMounted(() => {
  nextTick(() => {
    initChart();
  })
})

</script>

<style scoped lang="scss">
.t-sales {
  background-color: #ffffff;
  border-radius: 8px;

  &-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);

    > h5 {
      margin: 0;
      font-size: 16px;
      color: rgba(0, 0, 0, 0.8);
    }
  }

  &-content {
    padding: 20px;



  }
}
</style>

